package com.motu.vertx.module.utility.webhandler;

import com.motu.vertx.module.utility.webtool.BaseWebHandler;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.web.RoutingContext;
import io.vertx.ext.web.client.WebClient;
import io.vertx.sqlclient.Pool;

public class ServerreloadHandler extends BaseWebHandler{
	public static final String tableName = "webmanager_server_reload";
	private static Pool jdbcClientServer = null;

	public static void init(Pool jdbcServer){
		jdbcClientServer = jdbcServer;
	}
	public static void list(RoutingContext routingContext,JsonObject json,String adminName,WebClient client){
		getTableList(routingContext, jdbcClientServer,tableName);
	}
	
	/**
	 * 查询重载方法
	 * @param routingContext
	 * @param json
	 * @param adminName
	 */
	public static void search(RoutingContext routingContext, JsonObject json,String adminName,WebClient client) {
		String strWhere = " where 1=1 ";
		if (json.containsKey("key")) {
			String key = json.getString("key").toLowerCase();
			strWhere += " and (lower(method) like '%" + key + "%' or lower(des) like '%" + key + "%')";
		}
		String sql = "select count(1) from webmanager_server_reload " + strWhere;
		String sql2 = "select * from webmanager_server_reload " + strWhere + " limit ?,?;";
		JsonArray params2 = new JsonArray();
		int pageNo = json.getInteger("pageNo");
		int pageSize = json.getInteger("pageSize");
		int start = pageNo*pageSize;
		params2.add(start);
		params2.add(pageSize);
		searchFromTable(routingContext, jdbcClientServer, tableName, sql, new JsonArray(), sql2, params2);
	}
	
	public static void add(RoutingContext routingContext,JsonObject json,String adminName,WebClient client){
		addToTable(routingContext,jdbcClientServer, tableName,null);
	}

	public static void update(RoutingContext routingContext,JsonObject json,String adminName,WebClient client){
		
		updateToTable(routingContext,jdbcClientServer, tableName,null);
	}

	public static void getone(RoutingContext routingContext,JsonObject json,String adminName,WebClient client){
		getFromTable(routingContext,jdbcClientServer, tableName);

	}
	public static void delete(RoutingContext routingContext,JsonObject json,String adminName,WebClient client){
		deleteFromTable(routingContext,jdbcClientServer, tableName);
	}

	

}
